﻿using MedicalManagementAPP.AccountModule;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MedicalManagementAPP.Forms
{
    public partial class AdminForm : Form
    {
        LoginForm loginForm;
        Person user;
        string curSql;
        public AdminForm(LoginForm loginForm,Person person)
        {
            InitializeComponent();
            this.loginForm = loginForm;
            this.user = person;
            skinEngine1.SkinFile = @"irisskin2\Wave.ssk";
        }

        private void AdminForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            loginForm.Show();
        }

        private void UnlockCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (UnlockCheckBox.Checked)
            {
                dataGridView1.ReadOnly = false;
                UnlockCheckBox.ForeColor = Color.Red;
                SubmitButton.Enabled = true;
            }
            else
            {
                dataGridView1.ReadOnly = true;
                UnlockCheckBox.ForeColor = Color.Black;
                SubmitButton.Enabled = false;
            }
        }

        private void ShowInfo(string sql)
        {
            curSql = sql;
            dataGridView1.DataSource = Connection.SqlQuery(sql);
        }

        private void UpdateInfo()
        {
            bool flag = Connection.UpdateData(curSql, new System.Data.SqlClient.SqlParameter[0], (DataTable)dataGridView1.DataSource);
            if (flag) { MessageBox.Show("修改成功(但是不可变的项目不会被更改)"); } else { MessageBox.Show("修改失败"); }
            ShowInfo(curSql);
        }

        private void SubmitButton_Click(object sender, EventArgs e)
        {
            UpdateInfo();
        }
        private void DepartmentButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from Department");
        }
        private void WorkerButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from Workers");
        }

        private void MedicineButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from Medicines");
        }

        private void PatientButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from Patients");
        }

        private void RecordSetButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from RecordSet");
        }

        private void RecordButton_Click(object sender, EventArgs e)
        {
            ShowInfo("select * from MedicalRecords");
        }
    }
}
